/**
 * UserList.java
 * Purpose: Controller
 *
 * @version 1.0 4/23/11
 * @author Islam Al-Aarag
 */
package controllers;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import models.User;
import play.data.validation.Required;
import play.mvc.*;

public class UserList extends Controller {
	/**
	 * A method to get a list of users ordered by community contribution and
	 * render it to the corresponding page to view it.
	 * @author Islam Al-Aarag
	 */
	public static void getOrderedUser() {
		/******************* Testing *************************/
		/*
		 * for (int i = 0; i < 100; i++) { User u = new User("fat7y" + i,
		 * "male", "fat7y", "secret", new Date(), "fat7y@gmail.com", "cairo");
		 * u.contribution = i; u.save(); }
		 */
		/******************** End Testing ********************/
		List<User> orderedUsers = User.getListOfOrderedUsers();
		render(orderedUsers);
	}
	/**
	 * renders a list of users ordered by contribution but doesn't show user's whose contribution
	 * is less than 10
	 * @author omar fouda
	 */
	public static void getOrderedUser2() {
		/******************* Testing *************************/
		/*
		 * for (int i = 0; i < 100; i++) { User u = new User("fat7y" + i,
		 * "male", "fat7y", "secret", new Date(), "fat7y@gmail.com", "cairo");
		 * u.contribution = i; u.save(); }
		 */
		/******************** End Testing ********************/
		List<User> orderedUsers = User.getListOfOrderedUsers();
		List<User> usersWithNoZero = new ArrayList<User>();
			for(int i = 0; i< orderedUsers.size(); i++){
				if(orderedUsers.get(i).contribution > 10){
					usersWithNoZero.add(orderedUsers.get(i));
				}
			}
		renderTemplate("UserList/getOrderedUser2.html",usersWithNoZero);
	}

}
